package www.openteam.com.presenter.business;

import java.util.HashMap;

import www.openteam.com.base.BasePresenter;
import www.openteam.com.bean.ApprovalStatu;
import www.openteam.com.bean.CustomOrder;
import www.openteam.com.contract.business.QueryCustomOrderInfoContract;
import www.openteam.com.model.business.EditCustomOrderModel;
import www.openteam.com.model.business.NewBuildCustomOrderInfoModel;
import www.openteam.com.model.business.QueryCustomOrderInfoModel;
import www.openteam.com.mvp.IModel;
import www.openteam.com.ui.business.QueryCustomOrderInfoFragment;

/**
 * Created by kylin on 2016/11/14.
 */

public class QueryCustomOrderInfoPresenter extends BasePresenter<QueryCustomOrderInfoFragment>
        implements QueryCustomOrderInfoContract.QueryCustomOrderInfoPresenter {

    public void queryCustomOrderInfo(String rdsno,
                                     String custid,
                                     int pageSize) {
        ((QueryCustomOrderInfoModel) getiModelMap().get("queryCustomOrder"))
                .queryCustomOrderInfo(rdsno, custid, pageSize, new QueryCustomOrderInfoModel.QueryCustomOrderInfoOnListener() {
                    @Override
                    public void queryCOISuccess(CustomOrder customOrder) {
                        CustomOrder.DataEntity dataEntity = customOrder.getData().get(0);
//                        dataEntity.setRdsno("OpenTeam");
//                        dataEntity.setCustid("OpenTeam");
//                        dataEntity.setCustname("深圳开盟");

                        getIView().loadCOIData(customOrder);
                    }

                    @Override
                    public void queryCOIFail(Throwable throwable) {
                        getIView().hideCOIData(throwable);
                    }
                });


    }

    public void insertCustomOrderMainInfo(
            String custid, String businessno,
            String userid,
            String moneytype, String paytime
            , String sendtype, String custorderid
            , String alreadlypay, String inputdate
            , String inputer, String orderamount
            , String remark, String orderdate
            , String sendaddress, String istax
            , String taxrate, String invtype
            , String stype
    ) {
            ((QueryCustomOrderInfoModel) getiModelMap().get("queryCustomOrder"))
                    .insertCustomOrderMainInfo(custid, businessno, userid, moneytype, paytime,
                            sendtype, custorderid, alreadlypay, inputdate, inputer, orderamount,
                            remark, orderdate, sendaddress, istax, taxrate, invtype, stype
                            , new QueryCustomOrderInfoModel.InsertCustomOrderInfoOnListener() {
                                @Override
                                public void insertCOISuccess(ApprovalStatu approvalStatu) {
                                    getIView().insertCOIData(approvalStatu);
                                }

                                @Override
                                public void insertdCOIFail(Throwable throwable) {
                                    getIView().hideCOIData(throwable);
                                }
                            });
    }

    @Override
    public void updateCustomOrderMainInfo(int id, String rdsno, String custid, String userid, String moneytype, String paytime, String sendtype, String custorderid, String alreadlypay, String inputdate, String inputer, String orderamount, String remark, String orderdate, String sendaddress, String istax, String taxrate, String invtype, String stype) {
        ((QueryCustomOrderInfoModel) getiModelMap().get("queryCustomOrder"))
                .updateCustomOrderMainInfo(id, rdsno, custid, userid, moneytype, paytime, sendtype,
                        custorderid, alreadlypay, inputdate, inputer, orderamount, remark, orderdate,
                        sendaddress, istax, taxrate, invtype, stype, new QueryCustomOrderInfoModel.UpdateCustomOrderInfoOnListener() {
                            @Override
                            public void updateCOISuccess(ApprovalStatu updateState) {
                                getIView().updateCOIData(updateState);
                            }

                            @Override
                            public void updateCOIFail(Throwable throwable) {
                                getIView().hideCOIData(throwable);
                            }
                        });
    }
    @Override
    public HashMap<String, IModel> getiModelMap() {
        return loadModelMap(new QueryCustomOrderInfoModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String, IModel> hashMap = new HashMap<>();
        hashMap.put("queryCustomOrder", models[0]);

        return hashMap;
    }
}
